package com.nefu.editor.service.Impl;

import com.nefu.editor.common.EdiException;
import com.nefu.editor.core.mapper.NoticeMapper;
import com.nefu.editor.core.model.Notice;
import com.nefu.editor.service.NoticeService;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author chenchenT
 * @date : 18-11-16
 * @since : java 8
 */
@Service
public class NoticeServiceImpl implements NoticeService {

    private final NoticeMapper noticeMapper;

    public NoticeServiceImpl(NoticeMapper noticeMapper) {
        this.noticeMapper = noticeMapper;
    }

    @Override
    public Map<String, Object> getNoticeDetailByNoticeSystemId(Notice notice) throws EdiException {
        Map<String, Object> map = new HashMap<>(4);
        if (null != notice && null != notice.getSystemId()) {
            List<Notice> notices = noticeMapper.selectNoticeByCondition(notice);
            SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            if (null != notices && 1 == notices.size() && null != notices.get(0)) {
                notice = notices.get(0);
                map.put("systemId", notice.getSystemId());
                if (null != notice.getText()) {
                    map.put("text", notice.getText());
                } else {
                    map.put("text", null);
                }
                if (null != notice.getTime()) {
                    map.put("time", notice.getTime());
                } else {
                    map.put("time", null);
                }
                if (null != notice.getType()) {
                    map.put("type", notice.getType());
                } else {
                    map.put("type", null);
                }
            } else {
                throw new EdiException("参数有误!");
            }
        }
        return map;
    }
}
